package com.socialuni.sdk.user.phone;

import com.socialuni.sdk.model.DO.user.UserDO;
import com.socialuni.sdk.user.userManage.SocialUserManage;
import com.socialuni.sdk.model.DO.user.SocialPhoneNumDO;
import com.socialuni.sdk.utils.UserUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class SocialPhoneLoginDomain {
    @Resource
    SocialUserManage socialUserManage;
    @Resource
    SocialPhoneNumManage socialPhoneNumManage;

    //创建用户和手机号数据并绑定
    public UserDO phoneLogin(SocialPhoneNumDO phoneNumDO) {
        UserDO mineUser;
        if (phoneNumDO != null) {
            mineUser = UserUtils.get(phoneNumDO.getUserId());
        } else {
            mineUser = socialUserManage.createUserByPhoneLogin();
            socialPhoneNumManage.createUserPhoneNum(mineUser, phoneNumDO.getPhoneCountryCode(), phoneNumDO.getPhoneNum());
        }
        return mineUser;
    }
}
